home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / IDE / SUBARTIC / SUB_ARCT / LIB / SHRINK_W.JAV < prev    next >
Encoding:
Text File  |  1996-10-04  |  4.3 KB  |  143 lines

  1. package sub_arctic.lib;
  2.  
  3. import sub_arctic.constraints.std_function;
  4. import sub_arctic.output.drawable;
  5.  
  6. /** 
  7.  * A simple container class that sizes itself to fit its children (plus an
  8.  * optional border) then optionally draws a rectangle around its extent.  
  9.  *
  10.  * @author Scott Hudson
  11.  */
  12. public class shrink_wrap_container extends base_parent_interactor {
  13.  
  14.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  15.  
  16.   /** Space left at the right and bottom of our children */
  17.   protected int _border = 0;
  18.  
  19.   /** 
  20.    * Space left at the right and bottom of our children.
  21.    * @return int size of the border.
  22.    */
  23.   public int border() {return _border;}
  24.  
  25.   /** 
  26.    * Set space left at the right and bottom of our children.
  27.    * @param int bv new size of the border.
  28.    */
  29.   public void set_border(int bv) 
  30.     {
  31.       if (bv!=_border) {
  32.     _border = bv;
  33.     setup_constraints();
  34.       }
  35.     }
  36.  
  37.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  38.  
  39.   /** Flag bit position for flag indicating whether to draw the border. */
  40.   protected static final int DRAW_BORDER = FIRST_FREE_FLAG; 
  41.  
  42.   /** 
  43.    * Are we currently drawing the border rectangle.  We store the indicator
  44.    * for this in the interactor flags at the DRAW_BORDER bit position. 
  45.    * @return boolean indicating if we currently draw the border.
  46.    */
  47.   public boolean draw_border()
  48.     {
  49.       return flag_is_set(DRAW_BORDER);
  50.     }
  51.  
  52.   /** 
  53.    * Set whether we draw a rectangle at our border. 
  54.    * @param boolean v new value indicating whether we draw the border.
  55.    */
  56.   public void set_draw_border(boolean v)
  57.     {
  58.       if (flag_is_set(DRAW_BORDER) != v)
  59.     {
  60.           set_flag_bit(DRAW_BORDER, v);
  61.       damage_self();
  62.     }
  63.     }
  64.  
  65.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  66.  
  67.   /** 
  68.    * Set constraints corresponding to current border value.  These 
  69.    * constraints make our size large enough to cover the most outlying 
  70.    * child object (plus the current border on the right and bottom).
  71.    */ 
  72.   protected void setup_constraints()
  73.     {
  74.       /* set constraints on w/h to match max of children */
  75.       set_w_constraint(std_function.offset(MAX_CHILD.X2(), border()));
  76.       set_h_constraint(std_function.offset(MAX_CHILD.Y2(),border()));
  77.     }
  78.  
  79.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  80.  
  81.   /** 
  82.    * Full constructor.
  83.    * @param int     x         x position of the container.
  84.    * @param int     y         y position of the container.
  85.    * @param int     bd        size of the border.
  86.    * @param boolean draw_bord whether we draw a bounding rectangle.
  87.    */
  88.   public shrink_wrap_container(int x, int y, int bd, boolean draw_bord) 
  89. {
  90.       super(x,y);
  91.       set_flag_bit(DRAW_BORDER, draw_bord);
  92.       _border=bd;
  93.       /* note: don't call the set functions here, they check to see if
  94.        * the value is different and if not they don't do anything. This
  95.        * not desirable since we need to FORCE one computation of the
  96.        * constraints the first time.
  97.        */
  98.       setup_constraints();
  99.     }
  100.  
  101.    //had:
  102.    //* @exception general PROPAGATED
  103.  
  104.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  105.  
  106.    /** 
  107.     * Draw the object's current appearance.  This draws the children
  108.     * and then the optional border rectangle.
  109.     *
  110.     * @param drawable d the surface we draw on.
  111.     */
  112.   protected void draw_self_local(drawable d) 
  113. {
  114.       /* let superclass draw any children we have */
  115.       super.draw_self_local(d);
  116.  
  117.       /* optionally draw our border */
  118.       if (flag_is_set(DRAW_BORDER))
  119.         d.drawRect(0,0,w()-1,h()-1);    
  120.     }
  121.  
  122.     //had:
  123.     //* @exception general PROPAGATED
  124.  
  125.   /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
  126. }
  127. /*=========================== COPYRIGHT NOTICE ===========================
  128.  
  129. This file is part of the subArctic user interface toolkit.
  130.  
  131. Copyright (c) 1996 Scott Hudson and Ian Smith
  132. All rights reserved.
  133.  
  134. The subArctic system is freely available for most uses under the terms
  135. and conditions described in 
  136.   http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html 
  137. and appearing in full in the lib/interactor.java source file.
  138.  
  139. The current release and additional information about this software can be 
  140. found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
  141.  
  142. ========================================================================*/
  143.